package a.f.j;

import a.a.fb;
import a.c.d;
import a.c.e;
import a.c.q;
import a.c.w;
import a.c.x;

import java.util.Arrays;
import java.util.Comparator;

public class z
{
  public static final short a = 0;
  public static final short b = 1;
  private cb c;
  private i d;
  b_ e;
  c_[] g;
  private int[] h;
  private int[] i;
  private d[] j;
  private a.c.n k = null;
  public static int l;
  
  public z(cb paramcb)
  {
    this.c = paramcb;
    int m = 2 * this.c.a().j();
    this.d = new i(paramcb);
    this.h = new int[2 * this.c.a().l()];
    this.i = new int[m];
    this.j = new d[m];
    this.e = new b_(m);
    this.g = new c_[m];
  }
  
  public void a(a.c.n paramn)
  {
    this.k = paramn;
  }
  
  public void a(a.c.ab paramab)
  {
    boolean bool = ab.g;
    int m = ab.f;
    bb localbb = new bb(this.c, paramab);
    localbb.n();
    a.c.m localm = paramab.l();
    do
    {
      if (!localm.e()) {
        break;
      }
      d locald = localm.a();
      a.c.ab localab = a(locald, (short)1, localbb, null);
      this.d.a(localab, locald);
      if ((!bool) && (m != 0)) {
        return;
      }
      if (!bool)
      {
        if (a.i.n.c(this))
        {
          if (bool) {
            continue;
          }
          if (!this.c.h()) {
            throw new RuntimeException("Combinatorial Embedder failed !");
          }
        }
        localm.f();
      }
    } while (m == 0);
    localbb.o();
    if (!bool) {
      localbb.i();
    }
  }
  
  public int b(a.c.ab paramab)
  {
    boolean bool = ab.g;
    int n = ab.f;
    int m = 0;
    bb localbb = new bb(this.c, paramab);
    localbb.n();
    a.c.m localm = paramab.l();
    do
    {
      if (!localm.e()) {
        break;
      }
      d locald = localm.a();
      a.c.ab localab = a(locald, (short)0, localbb, null);
      if (bool) {
        break label114;
      }
      if (n != 0) {
        return m;
      }
      if (localab != null) {
        m += localab.size();
      }
      localm.f();
    } while (n == 0);
    localbb.o();
    if (!bool) {
      localbb.i();
    }
    label114:
    return m;
  }
  
  public void a(d paramd)
  {
    bb localbb = new bb(this.c);
    a.c.ab localab = a(paramd, (short)1, localbb, null);
    this.d.a(localab, paramd);
    localbb.i();
  }
  
  protected a.c.ab a(d paramd, short paramShort, bb parambb, d[] paramArrayOfd)
  {
    boolean bool = ab.g;
    int i1 = ab.f;
    q localq = parambb.a();
    e locale1 = localq.i();
    e locale2 = localq.i();
    a.c.m localm = paramd.e().n();
    Object localObject1;
    Object localObject2;
    do
    {
      do
      {
        if (!localm.e()) {
          break;
        }
        localObject1 = localm.a();
        localObject2 = parambb.b(this.c.c((d)localObject1));
        localq.a(locale1, (e)localObject2);
        localm.f();
        if (bool) {
          break label126;
        }
        if (i1 != 0) {
          break label119;
        }
      } while (i1 == 0);
    } while (bool);
    localm = paramd.f().n();
    label119:
    label126:
    do
    {
      if (!localm.e()) {
        break;
      }
      localObject1 = localm.a();
      localObject2 = parambb.b(this.c.c((d)localObject1));
      localq.a((e)localObject2, locale2);
      localm.f();
      if (bool) {
        break label237;
      }
      if (i1 != 0) {
        break label232;
      }
    } while (i1 == 0);
    do
    {
      if (bool) {
        break label242;
      }
      if (this.j.length >= localq.j()) {
        break;
      }
      break label242;
      this.j = new d[2 * this.j.length];
      if (bool) {
        break label283;
      }
      if (i1 != 0) {
        break label278;
      }
    } while (i1 == 0);
    label232:
    label237:
    label242:
    do
    {
      do
      {
        do
        {
          break label282;
          break label278;
          if (bool) {
            break;
          }
          if (this.h.length >= localq.l()) {
            break label278;
          }
          if (bool) {
            break label338;
          }
          this.h = new int[2 * this.h.length];
          if (i1 != 0) {
            break label337;
          }
        } while (i1 == 0);
        if (bool) {
          break;
        }
        if (this.i.length >= localq.j()) {
          break label324;
        }
        if (bool) {
          break label338;
        }
        this.i = new int[2 * this.i.length];
        if (i1 != 0) {
          break label337;
        }
      } while (i1 == 0);
    } while (bool);
    label278:
    label282:
    label283:
    label324:
    Arrays.fill(this.h, 1);
    label337:
    label338:
    if ((bool) || (this.k != null))
    {
      localm = this.c.a().w();
      do
      {
        if (!localm.e()) {
          break;
        }
        localObject1 = localm.a();
        localObject2 = parambb.k((d)localObject1);
        this.h[localObject2.d()] = c((d)localObject1);
        localm.f();
        if ((!bool) && (i1 != 0)) {
          break label507;
        }
      } while (i1 == 0);
    }
    if (!bool)
    {
      if (paramArrayOfd != null)
      {
        int m = 0;
        do
        {
          if (m >= paramArrayOfd.length) {
            break;
          }
          this.h[paramArrayOfd[m].d()] = 0;
          m++;
          if ((!bool) && (i1 != 0)) {
            break label507;
          }
        } while (i1 == 0);
      }
      if (!bool) {
        a(localq, locale1, locale2, true, this.h, this.i, this.j);
      }
    }
    label507:
    a.c.ab localab = fb.b(locale1, locale2, this.j);
    if (this.i[locale2.f()] == 2147483647) {
      localab = null;
    }
    if (!bool) {
      if ((localab == null) && (a.i.n.c(this)))
      {
        localObject1 = localq.B();
        a.a.m.a(localq, (x)localObject1);
        if (!bool) {}
        int n = ((x)localObject1).getInt(locale1) == ((x)localObject1).getInt(locale2) ? 1 : 0;
        localq.a((x)localObject1);
        if (n != 0) {
          throw new RuntimeException("Error computing shortest dual path");
        }
      }
    }
    if (!bool)
    {
      if (localab != null) {
        localab.o();
      }
    }
    else {
      localab.remove(localab.d());
    }
    localq.a(locale1);
    localq.a(locale2);
    switch (paramShort)
    {
    case 0: 
      return localab;
    case 1: 
      return a(parambb, localab);
    }
    throw new RuntimeException("Unknown return type style in EdgeRouter.routeEdge()");
  }
  
  private int c(d paramd)
  {
    if (!ab.g) {
      if (this.c.h(paramd)) {
        return this.k.getInt(this.c.b(paramd));
      }
    }
    return this.k.getInt(paramd);
  }
  
  private a.c.ab a(bb parambb, a.c.ab paramab)
  {
    boolean bool = ab.g;
    int m = ab.f;
    a.c.ab localab = new a.c.ab();
    if (!bool) {
      if (paramab == null) {
        return null;
      }
    }
    if ((bool) || (paramab.isEmpty())) {
      return localab;
    }
    d locald1 = null;
    d locald2 = null;
    a.c.m localm = paramab.l();
    localm.i();
    if (localm.e())
    {
      locald1 = localm.a();
      locald2 = parambb.j(locald1);
    }
    while (bool)
    {
      if (!bool)
      {
        if (m != 0) {
          break label124;
        }
        localab.a(locald2);
        localm.g();
      }
      if (m == 0) {
        break;
      }
    }
    label124:
    return localab;
  }
  
  public void a(int paramInt, a.c.ab paramab)
  {
    boolean bool = ab.g;
    int i6 = ab.f;
    int m = 0;
    int n = 0;
    int i3 = 0;
    bb localbb = new bb(this.c);
    localbb.n();
    label68:
    label324:
    do
    {
      if (m != 0) {
        break;
      }
      a.c.ab localab2 = new a.c.ab(paramab.l());
      if (bool) {
        break label556;
      }
      if (i6 != 0) {
        break label554;
      }
      a.c.m localm1 = localab2.l();
      d locald1;
      Object localObject;
      do
      {
        do
        {
          if (!localm1.e()) {
            break;
          }
          locald1 = localm1.a();
          localObject = this.c.m(locald1);
          if (i6 != 0) {
            break label159;
          }
          if (((a.c.m)localObject).k() == 1) {
            localab2.remove(locald1);
          }
          localm1.f();
        } while (i6 == 0);
      } while (bool);
      if ((!bool) && (localab2.size() == 0)) {
        break;
      }
      if (paramInt != -1) {
        if (n >= paramInt) {
          break;
        }
      }
      n++;
      localab2.a(new Comparator()
      {
        public int compare(Object paramAnonymousObject1, Object paramAnonymousObject2)
        {
          boolean bool = ab.g;
          d locald1 = (d)paramAnonymousObject1;
          d locald2 = (d)paramAnonymousObject2;
          int i = z.this.c.m(locald1).k();
          int j = z.this.c.m(locald2).k();
          if (!bool)
          {
            if (i == j) {
              return 0;
            }
            if (bool) {}
          }
          else if (i > j)
          {
            return -1;
          }
          return 1;
        }
      });
      localm1 = localab2.l();
      do
      {
        do
        {
          if (!localm1.e()) {
            break label527;
          }
          locald1 = localm1.a();
          localObject = new d[2 * this.c.m(locald1).k()];
          int i5 = 0;
          if (i6 != 0) {
            break label68;
          }
          a.c.m localm2 = this.c.m(locald1);
          a.c.ab localab1;
          int i2;
          do
          {
            do
            {
              if (!localm2.e()) {
                break label324;
              }
              d locald2 = localbb.k(localm2.a());
              localObject[(i5++)] = locald2;
              localObject[(i5++)] = localbb.b(locald2);
              localm2.f();
              if ((!bool) && (i6 != 0)) {
                break;
              }
            } while (i6 == 0);
            localab1 = a(locald1, (short)0, localbb, (d[])localObject);
            i2 = 0;
          } while (bool);
          if (!bool) {
            if (localab1.size() != 0)
            {
              localm2 = localab1.l();
              if (!localm2.e()) {}
            }
          }
          while (bool)
          {
            if (i6 != 0) {
              break label434;
            }
            if (this.h[localm2.a().d()] > 0) {
              i2++;
            }
            localm2.f();
            if (i6 == 0) {
              break;
            }
          }
          int i1 = this.c.m(locald1).k() - 1;
          if (!bool) {}
          int i4 = i1 > i2 ? 1 : 0;
          if (!bool)
          {
            if (i4 != 0)
            {
              i3 += i1 - i2;
              d(locald1);
              localab1 = a(locald1, (short)1, localbb, null);
              this.d.a(localab1, locald1);
              if (bool) {
                continue;
              }
              if (i6 == 0) {
                break;
              }
            }
            localm1.f();
          }
        } while (i6 == 0);
        m = 1;
      } while (bool);
    } while (i6 == 0);
    label159:
    label434:
    localbb.o();
    label527:
    if (!bool) {
      localbb.i();
    }
    label554:
    label556:
    if (!bool)
    {
      if (i3 == 0)
      {
        if (bool) {
          break label608;
        }
        a.i.n.a(this, 0, "  no improvement gained by rerouting edges");
      }
    }
    else if (i6 == 0) {
      return;
    }
    label608:
    a.i.n.a(this, 0, "  improvement: " + i3 + " crossing(s) less");
  }
  
  public void c(a.c.ab paramab)
  {
    a(-1, paramab);
  }
  
  private void d(d paramd)
  {
    boolean bool = ab.g;
    int m = ab.f;
    a.c.bb localbb = new a.c.bb();
    Object localObject = this.c.m(paramd);
    do
    {
      if (!((a.c.m)localObject).e()) {
        break;
      }
      d locald = ((a.c.m)localObject).a();
      if (!bool)
      {
        if (locald.f() != paramd.f()) {
          localbb.add(locald.f());
        }
        this.c.k(locald);
        ((a.c.m)localObject).f();
      }
    } while (m == 0);
    do
    {
      localObject = localbb.l();
      while (m == 0)
      {
        if (!((w)localObject).e()) {
          break;
        }
        this.c.h(((w)localObject).d());
        ((w)localObject).f();
      }
    } while (bool);
  }
  
  public void a(q paramq, e parame1, e parame2, boolean paramBoolean, int[] paramArrayOfInt1, int[] paramArrayOfInt2, d[] paramArrayOfd)
  {
    boolean bool = ab.g;
    int i5 = ab.f;
    int m = paramq.j();
    do
    {
      do
      {
        if (this.g.length >= m) {
          break;
        }
        this.g = new c_[2 * this.g.length];
      } while (i5 == 0);
    } while (bool);
    int n = 0;
    do
    {
      if (n >= m) {
        break;
      }
      paramArrayOfd[n] = null;
      paramArrayOfInt2[n] = 2147483647;
      n++;
      if ((!bool) && (i5 != 0)) {
        break label115;
      }
    } while (i5 == 0);
    n = parame1.f();
    paramArrayOfInt2[n] = 0;
    if (!bool) {
      this.e.a();
    }
    label115:
    do
    {
      e locale2;
      int i3;
      int i4;
      do
      {
        this.g[n] = this.e.a(0, parame1, this.g[n], n);
        int i2;
        while (locald == null)
        {
          if (this.e.c()) {
            break;
          }
          c_ localc_ = this.e.b();
          this.e.a(localc_);
          e locale1 = localc_.b;
          if (locale1 == parame2) {
            break;
          }
          int i1 = localc_.c;
          i2 = paramArrayOfInt2[i1];
          locald = locale1.h();
        }
        locale2 = locald.f();
        i3 = locale2.f();
        i4 = i2 + paramArrayOfInt1[locald.d()];
      } while (i5 != 0);
      if ((paramArrayOfd[i3] == null) && (locale2 != parame1))
      {
        paramArrayOfInt2[i3] = i4;
        this.g[i3] = this.e.a(i4, locale2, this.g[i3], i3);
        if ((!bool) && (i5 == 0)) {}
      }
      else
      {
        if (bool) {
          continue;
        }
        if (i4 >= paramArrayOfInt2[i3]) {
          break label345;
        }
        paramArrayOfInt2[i3] = i4;
        this.e.a(this.g[i3], i4);
      }
      paramArrayOfd[i3] = locald;
      d locald = locald.i();
    } while (i5 == 0);
    label345:
  }
  
  static class b_
  {
    private z.c_[] a;
    private int c;
    private int e;
    
    b_(int paramInt)
    {
      this.a = new z.c_[paramInt + 2];
      this.c = 0;
      this.e = paramInt;
    }
    
    public z.c_ a(int paramInt1, e parame, z.c_ paramc_, int paramInt2)
    {
      boolean bool = ab.g;
      if (!bool) {
        if (this.c == this.e)
        {
          this.e += 1024;
          localObject = new z.c_[this.e + 2];
          System.arraycopy(this.a, 0, localObject, 0, this.a.length);
          this.a = ((z.c_[])localObject);
        }
      }
      this.c += 1;
      if (!bool) {
        if (paramc_ == null)
        {
          localObject = new z.c_(paramInt1, parame, this.c, paramInt2);
          if (bool) {
            break label150;
          }
          if (ab.f == 0) {
            break label140;
          }
        }
      }
      Object localObject = paramc_;
      paramc_.a = paramInt1;
      paramc_.b = parame;
      paramc_.d = this.c;
      paramc_.c = paramInt2;
      label140:
      a(this.c, (z.c_)localObject);
      label150:
      return localObject;
    }
    
    public void a()
    {
      boolean bool = ab.g;
      int j = ab.f;
      int i = 1;
      if (i <= this.c) {}
      while (bool)
      {
        this.a[i] = null;
        i++;
        if ((!bool) && (j != 0)) {
          return;
        }
        if (j == 0) {
          break;
        }
      }
      this.c = 0;
    }
    
    public void a(int paramInt, z.c_ paramc_)
    {
      boolean bool = ab.g;
      int j = ab.f;
      this.a[0] = paramc_;
      int i = paramInt / 2;
      z.c_ localc_ = this.a[i];
      if (localc_.a > paramc_.a) {
        this.a[paramInt] = localc_;
      }
      do
      {
        localc_.d = paramInt;
        paramInt = i;
        i >>= 1;
        localc_ = this.a[i];
        if ((!bool) && (j != 0)) {
          return;
        }
        if (j == 0) {
          break;
        }
        this.a[paramInt] = paramc_;
      } while (bool);
      paramc_.d = paramInt;
    }
    
    public void b(int paramInt, z.c_ paramc_)
    {
      boolean bool = ab.g;
      int j = ab.f;
      int i = paramInt << 1;
      this.a[(this.c + 1)] = this.a[this.c];
      if (i <= this.c) {}
      label117:
      do
      {
        z.c_ localc_ = this.a[i];
        if ((!bool) && (j != 0)) {
          return;
        }
        if (!bool) {
          if (i < this.c)
          {
            if (bool) {
              break label117;
            }
            if (this.a[(i + 1)].a < localc_.a) {
              localc_ = this.a[(++i)];
            }
          }
        }
        if (!bool)
        {
          if (paramc_.a > localc_.a)
          {
            this.a[paramInt] = localc_;
            localc_.d = paramInt;
            paramInt = i;
          }
        }
        else
        {
          i <<= 1;
          if (j == 0) {
            break;
          }
        }
        this.a[paramInt] = paramc_;
      } while (bool);
      paramc_.d = paramInt;
    }
    
    public void a(z.c_ paramc_)
    {
      boolean bool = ab.g;
      z.c_ localc_ = this.a[this.c];
      this.a[this.c] = null;
      this.c -= 1;
      if ((bool) || (paramc_ != localc_))
      {
        if (!bool)
        {
          if (localc_.a > paramc_.a)
          {
            if (bool) {
              break label83;
            }
            b(paramc_.d, localc_);
          }
        }
        else if (ab.f == 0) {
          return;
        }
        label83:
        a(paramc_.d, localc_);
      }
    }
    
    public void a(z.c_ paramc_, int paramInt)
    {
      paramc_.a = paramInt;
      a(paramc_.d, paramc_);
    }
    
    public z.c_ b()
    {
      return this.a[1];
    }
    
    public boolean c()
    {
      if (!ab.g) {}
      return this.c == 0;
    }
    
    public int e()
    {
      return this.c;
    }
  }
  
  static class c_
  {
    int a;
    e b;
    int c;
    int d;
    
    c_(int paramInt1, e parame, int paramInt2, int paramInt3)
    {
      this.a = paramInt1;
      this.b = parame;
      this.d = paramInt2;
      this.c = paramInt3;
    }
  }
}



/* Location:           E:\idea\

 * Qualified Name:     a.f.j.z

 * JD-Core Version:    0.7.0.1

 */